<template>
  <div>
    <div class="search">
      <van-search v-model="query.userName" show-action placeholder="请输入搜索关键词" @search="onSearch">
        <template #action>
          <div class="button" @click="onSearch">搜索</div>
        </template>
      </van-search>
    </div>
    <div class="list">
      <van-list v-model="loading" :finished="finished" finished-text="~已经到底啦" @load="onLoad">
        <div class="list-item" v-for="(data, index) in list" :key="index">
          <div class="title">
            <span class="dept">{{ data.deptName }}</span>
            <span class="name">{{ data.userName }}</span>
          </div>
          <van-divider :style="{ color: '#E5E6EB;', borderColor: '#E5E6EB', padding: '16px 0', margin: '0' }">
          </van-divider>
          <div class="value">
            <div class="value-unit">
              <span class="value-title">超时次数</span>
              <div class="value-num">{{ data.timeOutNum }}</div>
            </div>
            <div class="value-unit">
              <span class="value-title">超时率</span>
              <div class="value-num">{{ Number(data.timeOutRate) * 100 + '%' }}</div>
            </div>
            <div class="value-unit">
              <span class="value-title">客户会话<br />超时率</span>
              <div class="value-num">{{ Number(data.chatTimeOutRate) * 100 + '%' }}</div>
            </div>
            <div class="value-unit">
              <span class="value-title">客群会话<br />超时率</span>
              <div class="value-num">{{ Number(data.groupChatTimeOutRate) * 100 + '%' }}</div>
            </div>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script>
  import { getWeeklyMemeberList } from '@/api/quality.js'
  export default {
    name: 'record-detail',
    data() {
      return {
        loading: false,
        finished: false,
        list: [],
        total: 0,
        id: '',
        query: {
          pageSize: 10,
          pageNum: 1,
          userName: ''
        }
      }
    },
    methods: {
      onLoad() {
        if (this.list.length < this.total) {
          this.query.pageNum++
          this.loading = true
          getWeeklyMemeberList(this.id, this.query)
            .then((res) => {
              this.list = this.list.contact(res.rows)
              this.total = Number(res.total)
              if (this.list.length == this.total) {
                this.finished = true
              }
              this.loading = false
            })
            .finally(() => {
              this.loading = false
            })
        } else {
          this.finished = true
          this.loading = false
        }
      },
      onSearch() {
        this.query.pageNum = 1
        this.getList()
      },
      getList() {
        this.loading = true
        getWeeklyMemeberList(this.id, this.query)
          .then((res) => {
            this.list = res.rows
            this.total = Number(res.total)
            if (this.list.length == this.total) {
              this.finished = true
            }
            this.loading = false
          })
          .finally(() => {
            this.loading = false
          })
      }
    },
    mounted() {
      this.id = this.$route.query.id
      this.getList()
    }
  }
</script>

<style lang="less" scoped>
  /deep/ .van-search__action {
    padding: 0 16px;
    line-height: 68px;
  }
  /deep/ .van-search__content {
    height: 36px;
    background: #f2f3f5;
    border-radius: 6px;
  }
  /deep/ .van-search {
    padding: 0 0 0 16px;
  }
  /deep/ .van-list__finished-text {
    font-size: 14px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 400;
    color: #c9cdd4;
    line-height: 16px;
  }
  .search {
    height: 68px;
    background: #ffffff;
    position: sticky;
    top: 0;
    .button {
      font-size: 15px;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #07c160;
    }
  }
  .list {
    padding: 24px 16px;
    .list-item {
      margin-bottom: 24px;
      padding: 24px 16px;
      background: #fff;
      border-radius: 16px;
      border: 1px solid #e5e6eb;
      .title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .dept {
          flex: 1;
          width: 0;
          margin-right: 24px;
          font-size: 12px;
          font-weight: 600;
          color: #1d2129;
          line-height: 16px;
        }
        .name {
          flex-shrink: 0;
          font-size: 16px;
          font-weight: 700;
          color: #009849;
          line-height: 16px;
        }
      }
      .value {
        display: flex;
        justify-content: space-between;
        margin-top: 6px;
        .value-unit {
          height: 70px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .value-title {
            font-size: 12px;
            font-weight: 500;
            color: #4e5969;
            line-height: 18px;
          }
          .value-num {
            font-size: 24px;
            font-weight: 800;
            color: #1d2129;
            line-height: 24px;
          }
        }
      }
    }
  }
</style>
